package com.qf.controller;

import com.qf.pojo.DtsAdmin;

import com.qf.service.DtsBrandService;
import com.qf.service.DtsCommentService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/comment")
public class CommentController {

    @Autowired
    DtsBrandService dtsBrandService;

    @Autowired
    DtsCommentService commentService;



    @GetMapping("/list")
    public Object list(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                       @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
                       Integer userId, Integer valueId, String sort, String order) {
        Subject subject = SecurityUtils.getSubject();
        DtsAdmin admin = (DtsAdmin) subject.getPrincipal();
        List<Integer> brandIds = null;
        if (subject.hasRole("品牌制造商")) {
            brandIds = dtsBrandService.findBreadAdminId(admin.getId());
        }
        Map<String, Object> data = commentService.queryPage(page, limit, userId, valueId, sort, order);

        return ResponseUtil.ok(data);

    }
}
